<div class="col-lg-12">

  <% if params[:action] == 'recently_commented' %>
  <h2><%=translation('questions.index.recently_commented')%> <small class="d-md-none d-lg-inline"><%=translation('questions.index.recently_commented_questions')%></small></h2>
  <% elsif params[:action] == 'popular' %>
  <h2><%=translation('questions.index.popular_questions')%> <small class="d-md-none d-lg-inline"><%=translation('questions.index.most_viewed_questions')%></small></h2>
  <% elsif params[:action] == 'unanswered' %>
  <h2><%=translation('questions.index.unanswered_questions')%> <small class="d-md-none d-lg-inline"><%=translation('questions.index.unanswered_questions')%></small></h2>
  <% elsif params[:action] == 'liked' %>
  <h2><%=translation('questions.index.liked_questions')%> <small class="d-md-none d-lg-inline"><%=translation('questions.index.most_liked_questions')%></small></h2>
  <% else %>
  <div class="text-center">
    <% cache('feature_questions-header', skip_digest: true) do %>
      <%= feature('questions-header') %>
    <% end %>
  </div>
  <% end %>

  <hr />

  <div class="row">
    <div class="col-lg-6" style="margin-top: 20px;">
      <h4><%=translation('questions.index.ask_question')%></h4>
      <% if !current_user %>
        <p><%=translation('questions.index.to_ask_question')%><a href="/login?return_to=/questions"> <%=translation('questions.index.log_in')%> </a><%=translation('questions.index.or')%> <a href="/signup?return_to=/questions"><%=translation('questions.index.sign_up')%></a> 
          <%=translation('questions.index.first')%>.</p>
      <% end %>
      <form id="questions_searchform" role="search" autocomplete="off" action="/post">
        <div class="input-group">
          <input aria-label="Type your question" tabindex="1" id="questions_searchform_input" type="text" name="title" class="<%= "disabled " if !current_user %>form-control search-query typeahead" qryType="questions" placeholder="type your question">
          <input type="hidden" name="tags" value="question:general">
          <input type="hidden" name="template" value="question">
          <input type="hidden" name="redirect" value="question">
          <div class="input-group-append">
              <% if !current_user %>
              <a id="question_search"  class="btn btn-primary btn-md index-follow-buttons follow-btn-remote requireLogin" href="/questions/" data-remote="true" onclick="return theQuestion();" rel="tooltip" title="Ask a question with the entered title">Continue</a>
              <% else %>
              <button id="question_search" type="submit" rel="tooltip" title="Ask a question with the entered title" class="btn btn-primary">Continue</button>
              <% end %> 
          </div>
        </div>
      </form>
    </div>
    <div class="col-lg-6" style="margin-top: 20px;">
      <% if params[:controller] == 'questions' %>
        <%= render partial: 'tag/sorting' %>
      <% end %>
    </div>
  </div>

  <hr />

  <%= render :partial => "notes/format_toggle" %>

  <ul class="nav nav-tabs">
    <li class="nav-item">
      <a class="nav-link <% if params[:action] == "index" %> active <% end %>" href="/questions/">
        <i class="fa fa-refresh"></i> <span class="d-none d-lg-inline"><%=translation('questions.index.recently_asked')%></span>
      </a>
    </li>
    <li class="nav-item">
      <a class="nav-link <% if params[:action] == "recently_commented" %> active <% end %>" href="/questions/recently_commented/">
        <i class="fa fa-check"></i> <span class="d-none d-lg-inline"><%=translation('questions.index.recently_commented')%></span>
      </a>
    </li>
    <li class="nav-item">
    <a class="nav-link <% if params[:action] == "popular" %> active <% end %>" href="/questions/popular/">
        <i class="fa fa-bolt"></i> <span class="d-none d-lg-inline"><%=translation('questions.index.popular')%></span>
      </a>
    </li>
    <li class="nav-item">
    <a class="nav-link <% if params[:action] == "unanswered" %> active <% end %>" href="/questions/unanswered/">
        <i class="fa fa-question-circle"></i> <span class="d-none d-lg-inline"><%=translation('questions.index.unanswered')%></span>
      </a>
    </li>
    <li class="nav-item">
    <a class="nav-link <% if params[:action] == "liked" %> active <%end %>" href="/questions/liked/">
        <i class="fa fa-star-o"></i> <span class="d-none d-lg-inline"><%=translation('questions.index.liked')%></span>
      </a>
    </li>
  </ul>

  <%= render :partial => "questions/questions" %>

</div>
<% if !current_user %>
<script>
    function theQuestion () {
        // return true or false, depending on whether you want to allow the `href` property to follow through or not
        document.getElementById('question_search').setAttribute("href", '/questions/new?title='+ encodeURI($('#questions_searchform_input').val()) +'&tags=question%3Ageneral&template=question&redirect=question');
        return true;
      }
    </script>
    <% else %>
    <script>
      $('#question_search').on('click', function(e) {
        var postQuery = '/post?tags=question:general&template=question&title=' + encodeURI($('#questions_searchform_input').val()) + '&redirect=question';

        $.getJSON(postQuery);
      });
    </script>
</script>
<% end %>
<%= stylesheet_link_tag "dashboard" %>
